]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ShellIdleMonitor: turn it into a singleton
authorGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 16 Aug 2012 19:11:54 +0000 (21:11 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 16 Aug 2012 23:32:02 +0000 (01:32 +0200)
It doesn't make sense to have multiple ShellIdleMonitors, since
each has its own GDK filter function, but they all get the same
events. In preparation for having it accessed from other places
than the message tray, make it a singleton.

https://bugzilla.gnome.org/show_bug.cgi?id=682041

js/ui/messageTray.js
src/shell-idle-monitor.c
src/shell-idle-monitor.h

index 1ce114e6d858cd52a500e80cac463e628ba6cf17..eabf6a7d538e51e14a2401ef1fac331fffa0d346 100644 (file)
@@ -1508,7 +1508,7 @@ const MessageTray = new Lang.Class({
         this._idleMonitorWatchId = 0;
         this._backFromAway = false;
 
-        this.idleMonitor = new Shell.IdleMonitor();
+        this.idleMonitor = Shell.IdleMonitor.get();
 
         // To simplify the summary item animation code, we pretend
         // that there's an invisible SummaryItem to the left of the
index 22581d100af948f062abfdf60a112bbf70c69b05..592f4772c177e3bcacd5a19e193cf7fdca8e42db 100644 (file)
@@ -316,15 +316,21 @@ shell_idle_monitor_init (ShellIdleMonitor *monitor)
         monitor->priv->counter = None;
 }
 
+/**
+ * shell_idle_monitor_get:
+ *
+ * Returns: (transfer none): the global #ShellIdleMonitor.
+ */
 ShellIdleMonitor *
-shell_idle_monitor_new (void)
+shell_idle_monitor_get (void)
 {
-        GObject *idle_monitor;
+        static ShellIdleMonitor *idle_monitor;
 
-        idle_monitor = g_object_new (SHELL_TYPE_IDLE_MONITOR,
-                                     NULL);
+        if (G_UNLIKELY (idle_monitor == NULL))
+                idle_monitor = g_object_new (SHELL_TYPE_IDLE_MONITOR,
+                                             NULL);
 
-        return SHELL_IDLE_MONITOR (idle_monitor);
+        return idle_monitor;
 }
 
 static gboolean
index 1086d9216e8a428082576066a43f326be3e9968c..2fcd0820b432937217baaed967ae22201a4c23e6 100644 (file)
@@ -56,7 +56,7 @@ typedef void (*ShellIdleMonitorWatchFunc) (ShellIdleMonitor *monitor,
 
 GType              shell_idle_monitor_get_type     (void);
 
-ShellIdleMonitor * shell_idle_monitor_new          (void);
+ShellIdleMonitor * shell_idle_monitor_get          (void);
 
 guint              shell_idle_monitor_add_watch    (ShellIdleMonitor         *monitor,
                                                     guint                     interval,